<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="客户名称" prop="custid">
        <el-input
          v-model="queryParams.custid"
          placeholder="请输入客户名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="房产编号" prop="hourseid">
        <el-input
          v-model="queryParams.hourseid"
          placeholder="请输入房产编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="业务员" prop="saleperson">
        <el-input
          v-model="queryParams.saleperson"
          placeholder="请输入业务员"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="状态" prop="invalid">
        <el-input
          v-model="queryParams.invalid"
          placeholder="请输入有效	是否有效"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>


    <el-row :gutter="10" class="mb8">




      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['house_sale:buyhouse:remove']"
        >删除</el-button>
      </el-col>


      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>


    <el-table v-loading="loading" :data="buyhouseList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="编号" align="center" prop="buyid" />
      <el-table-column label="客户名称" align="center" prop="custname" />
      <el-table-column label="房产名称" align="center" prop="housename" width="110px"/>
      <el-table-column label="业务员" align="center" prop="saleperson" />
      <el-table-column label="付款方案编号" align="center" prop="psid" />


      <el-table-column label="成交单价" align="center" prop="unitprice" />


      <el-table-column label="装修单价" align="center" prop="fitmentunitprice" />
      <el-table-column label="签约单价" align="center" prop="signunitprice" />
      <el-table-column label="购房总款" align="center" prop="totalmoney" />
      <el-table-column label="装修总款" align="center" prop="fitmenttotalprice" />
      <el-table-column label="签约总款" align="center" prop="signtotalprice" />
      <el-table-column label="按揭银行" align="center" prop="bankid" />
      <el-table-column label="首期款" align="center" prop="firstmoney" />
      <el-table-column label="装修首付款" align="center" prop="fitmentfirstprice" />
      <el-table-column label="装修尾款" align="center" prop="fitmentlastprice" />
      <el-table-column label="按揭金额" align="center" prop="bankmoney" />
      <el-table-column label="购买时间" align="center" prop="buytime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.buytime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="签约时间" align="center" prop="signtime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.signtime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>


      <!-- <el-table-column label="有效	是否有效" align="center" prop="invalid" /> -->

    <el-table-column label="佣金比例" align="center" prop="commisionPercent" />
    <el-table-column label="应付佣金" align="center" prop="commisionMoney" />
    <el-table-column label="已付佣金" align="center" prop="commisionpaid" />
    <el-table-column label="状态" align="center" prop="oprtype" />
      <el-table-column label="操作" fixed="right" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button v-if="scope.row.oprtype === '换房' || scope.row.oprtype === '买房'"
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
          >收款</el-button>
         <!-- v-hasPermi="['house_sale:buyhouse:edit']" -->
        </template>
      </el-table-column>
    </el-table>


    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />


  </div>
</template>
<script>
import { listBuyHouse1, getBuyHouse, delBuyHouse, addBuyHouse, updateBuyHouse } from "@/api/house_sale/BuyHouse";


export default {
  name: "Buyhouse",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 购买房产表格数据
      buyhouseList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        custid: null,
        hourseid: null,


        buytime: null,
        saleperson: null,


        invalid: null,


      },
      // 表单参数
      form: {},


    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询购买房产列表 */
    getList() {
      this.loading = true;
      listBuyHouse1(this.queryParams).then(response => {
        this.buyhouseList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },


    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.buyid)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加购买房产";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {


      const buyid = row.buyid ;
      const custname = row.custname;
      const housename = row.housename;
      const totalmoney = row.totalmoney;
      const hourseid = row.hourseid;
      this.$router.push( {
        path:"/house_sale/buyhouse/finance/"+buyid,
        query: {
         custname:custname,
         housename:housename,
         totalmoney:totalmoney,
         hourseid:hourseid
       }
     })


    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.buyid != null) {
            updateBuyhouse(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addBuyhouse(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const buyids = row.buyid || this.ids;
      this.$modal.confirm('是否确认删除购买房产编号为"' + buyids + '"的数据项？').then(function() {
        return delBuyhouse(buyids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('house_sale/buyhouse/export', {
        ...this.queryParams
      }, `buyhouse_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
